package action;
/**
 * 取消收藏
 */

import dao.CollectDao;
import po.Collect;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Writer;

@WebServlet(urlPatterns = "/user/action/CancelCollectServlet")
public class CancelCollectServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String userId = req.getParameter("userId");
        String product = req.getParameter("product");
        Collect collect = new Collect();
        collect.setProduct(product);
        collect.setUserid(userId);
        CollectDao collectDao = new CollectDao();
        Integer row = collectDao.delete(collect);
        Writer writer = null;
        try {
            writer = resp.getWriter();
            if (row>0){
                writer.write("yes");
            }else {
                writer.write("no");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
